package com.yunfeng.supercall.bean;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 聊天消息的实体类
 * 
 * @author 洋
 * 
 */
public class ChatMessageBean implements Parcelable, Comparable<ChatMessageBean> {

	public static final int TYPE_TEXT = 0;
	public static final int TYPE_VOICE = 1;
	public static final int TYPE_PIC = 2;
	public static final int TYPE_LOCATION = 3;
	private int id;
	private int chatType;
	private String content;
	private boolean sendFromMySelf;
	private long receiveTime;
	private String msgFrom;
	private String msgTo;
	private String msgId;
	private int voiceLenth;
	private boolean hasRead;
	private int unreadCount; 
	public int getUnreadCount() {
		return unreadCount;
	}

	public void setUnreadCount(int unreadCount) {
		this.unreadCount = unreadCount;
	}

	public static final Creator<ChatMessageBean> CREATOR = new Creator<ChatMessageBean>() {

		@Override
		public ChatMessageBean[] newArray(int size) {
			// TODO Auto-generated method stub
			return new ChatMessageBean[size];
		}

		@Override
		public ChatMessageBean createFromParcel(Parcel source) {
			// TODO Auto-generated method stub
			ChatMessageBean mBean = new ChatMessageBean();
			mBean.id = source.readInt();
			mBean.voiceLenth = source.readInt();
			mBean.chatType = source.readInt();
			mBean.receiveTime = source.readLong();
			mBean.sendFromMySelf = source.readInt() > 0? true : false;
			mBean.msgFrom = source.readString();
			mBean.content = source.readString();
			mBean.msgTo = source.readString();
			mBean.msgId = source.readString();
			
			return new ChatMessageBean(source);
		}
	};

	public ChatMessageBean() {
	}

	public boolean isHasRead() {
		return sendFromMySelf ? true : hasRead;
	}

	public void setHasRead(boolean hasRead) {
		this.hasRead = hasRead;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeInt(id);
		dest.writeInt(voiceLenth);
		dest.writeInt(chatType);
		dest.writeLong(receiveTime);
		dest.writeInt(sendFromMySelf ? 0 : 1);
		dest.writeString(msgFrom);
		dest.writeString(content);
		dest.writeString(msgTo);
		dest.writeString(msgId);
	}

	public ChatMessageBean(Parcel parcel) {
		id = parcel.readInt();
		voiceLenth = parcel.readInt();
		chatType = parcel.readInt();
		receiveTime = parcel.readLong();
		sendFromMySelf = parcel.readInt() == 0;
		msgFrom = parcel.readString();
		content = parcel.readString();
		msgTo = parcel.readString();
		msgId = parcel.readString();
	}

	public int getVoiceLenth() {
		if (voiceLenth == 0) {
			return 1;
		}
		return voiceLenth;
	}

	public void setVoiceLenth(int voiceLenth) {
		this.voiceLenth = voiceLenth;
	}

	public String getMsgId() {
		return msgId;
	}

	public void setMsgId(String msgId) {
		this.msgId = msgId;
	}

	public String getMsgTo() {
		return msgTo;
	}

	public void setMsgTo(String msgTo) {
		this.msgTo = msgTo;
	}

	public int getChatType() {
		return chatType;
	}

	public void setChatType(int chatType) {
		this.chatType = chatType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public boolean isSendFromMySelf() {
		return sendFromMySelf;
	}

	public void setSendFromMySelf(boolean sendFromMySelf) {
		this.sendFromMySelf = sendFromMySelf;
	}

	public long getReceiveTime() {
		return receiveTime;
	}

	public void setReceiveTime(long receiveTime) {
		this.receiveTime = receiveTime;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getMsgFrom() {
		return msgFrom;
	}

	public void setMsgFrom(String msgFrom) {
		this.msgFrom = msgFrom;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int compareTo(ChatMessageBean another) {
		// TODO Auto-generated method stub
		return 0;
	}

}
